package com.functest.orm

import com.functest.framework.BaseFunctionalTest
import org.testng.annotations.Test

/**
 * Created with IntelliJ IDEA.
 * User: KovalevAS
 * Date: 06.09.13
 * Time: 18:19
 * To change this template use File | Settings | File Templates.
 */
class FieldReferenceTest extends BaseFunctionalTest {


    @Test
    void equalsTest() {
        asTest {
            String fieldName = 'fieldName'
            MapperFields builder = new MapperFields().with {
                field(fieldName)
                delegate as MapperFields
            }
            Mapper mapper = new Mapper(builder)
            FieldReference x = new FieldReference(mapper, fieldName)
            FieldReference y = new FieldReference(mapper, fieldName)
            FieldReference z = new FieldReference(mapper, fieldName)
            FieldReference notX = new FieldReference(mapper, 'name')

            asStep("reflexive test") {
                com.functest.framework.Assertions.weakAssertSilently("reflexive test failed", x.equals(x))
            }
            asStep("symmetric test") {
                com.functest.framework.Assertions.weakAssertSilently("symmetric test failed",
                        x.equals(y)
                                && y.equals(x)
                                && !x.equals(notX)
                                && !notX.equals(x))
            }
            asStep("transitive test") {
                com.functest.framework.Assertions.weakAssertSilently("transitive test failed",
                        x.equals(y) && y.equals(z) && x.equals(z))
            }
            asStep("consistent test") {
                1.upto(10) {
                    com.functest.framework.Assertions.weakAssertSilently("consistent test failed", x.equals(y) && !x.equals(notX))
                }
            }
            asStep("null test") {
                com.functest.framework.Assertions.weakAssertSilently("null test failed", !x.equals(null))
            }
        }
    }


}
